package com.sctvcloud.bazhong.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.sctvcloud.bazhong.R;
import com.sctvcloud.bazhong.beans.CityServiceBean;
import com.sctvcloud.bazhong.beans.FCityState;
import com.sctvcloud.bazhong.beans.FCountyState;
import com.sctvcloud.bazhong.beans.ItemStatus;

import java.util.ArrayList;
import java.util.List;

public class ExchangeCityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<CityServiceBean> stateList;
    private String selectedCity;
    private OnItemClickListener listener;
    private Context ctx;

    static class CityViewHolder extends RecyclerView.ViewHolder {
        CustomFontTextView cityName;
        LinearLayout cityLayout;

        public CityViewHolder(View view) {
            super(view);
            cityName = (CustomFontTextView) view.findViewById(R.id.city_name);
            cityLayout = (LinearLayout) view.findViewById(R.id.city_layout);
        }
    }


    public ExchangeCityListAdapter(Context context, List<CityServiceBean> list, String city) {
        stateList = list;
        selectedCity = city;
        ctx = context;
    }

    public OnItemClickListener getListener() {
        return listener;
    }

    public void setListener(OnItemClickListener listener) {
        this.listener = listener;
    }

    public void setData(List<CityServiceBean> list){
        if(null!=list){
            stateList = list;
        }
    }
    @Override
    public int getItemViewType(int position) {
        return 0;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        RecyclerView.ViewHolder holder = null;
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.exchange_city_list_item, parent, false);
        holder = new CityViewHolder(view);

        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        final CityServiceBean ct = stateList.get(position);

        final CityViewHolder cityViewHolder = (CityViewHolder) holder;
//        if (!TextUtils.isEmpty(selectedCity) && selectedCity.equalsIgnoreCase(ct.getCityName())) {
//            cityViewHolder.cityName.setTextColor(ctx.getResources().getColor(R.color.colorTimeBg));
//        } else {
//            cityViewHolder.cityName.setTextColor(ctx.getResources().getColor(R.color.colorBlack22));
//        }
        cityViewHolder.cityName.setText(ct.getCityName());
        cityViewHolder.cityLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != listener) {
                    listener.onCityItemClick(ct);
                }
            }
        });

    }

    //返回子项个数
    @Override
    public int getItemCount() {
        if (null != stateList && stateList.size() > 0) {
            return stateList.size();
        }
        return 0;
    }

    public interface OnItemClickListener {
        void onCityItemClick(CityServiceBean cityState);
    }

}
